<!DOCTYPE html>
<html class="x-admin-sm">
{include file='public/header'}
<script src="/admin/xadmin/lib/layui/upload.js" charset="utf-8"></script>
<script src="/admin/xadmin/js/jquery.gridly.js?vension=1.0" charset="utf-8"></script>
<link rel="stylesheet" href="/admin/xadmin/css/jquery.gridly.css">
<style>
    .gridly {
        position: relative;
    }

    .moneyContent {
        padding: 15px 10px;
        border: 1px solid #c2c2c2;
        background-color: #fff;
    }

    .moneyContent .content {
        border: 1px solid #dcdcdc;
        padding: 10px 0
    }

    .moneyContent .content div {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .moneyContent .content .title {
        font-size: 24px;
    }

    .moneyContent .content .title,
    .moneyContent .content .startSet {
        margin-left: 10px;
    }

    .moneyContent .content .startSet i {
        color: #fa2a2d;
    }

    .moneyContent .content .tip {
        border-radius: 15px 0 0 15px;
        background-color: #fa2a2d;
        color: #fff;
        padding: 2px 8px;
        font-size: 12px;
    }

    .moneyContent .foot {
        display: flex;
        align-items: center;
        /* justify-content: flex-end; */
        justify-content: space-between;
        margin-top: 5px;
    }

    .layui-form-radio {
        margin: 0;
        font-size: 16px;
    }

    .layui-form-radio:hover *,
    .layui-form-radioed,
    .layui-form-radioed>i {
        color: #1e9fff;
    }

    .layui-row {
        display: flex;
        justify-content: center;
    }

    .btn {
        display: flex;
        justify-content: center;
        margin-top: 10px;
    }

    .moneyTemplate .layui-form-label {
        width: 95px;
        padding: 9px 5px;
    }

    .layui-layer-page .layui-layer-content {
        overflow: visible;
    }

    .layui-tab-content {
        padding-bottom: 0;
    }

    .item {
        display: flex;
        width: 80%;
    }

    .layui-input-block {
        margin-left: 165px;
        display: flex;
        align-items: center;
    }

    #selectAccount .layui-input-block {
        margin-left: 0;
    }

    .designated_amount_echo {
        width: 50%;
    }

    .designated_amount_echo .item {
        display: flex;
        justify-content: space-between;
        margin-top: 10px;
        height: 38px;
    }

    .designated_amount_echo .item div {
        display: flex;
        align-items: center;
    }

    .designated_amount_echo .item .content div {
        margin-right: 10px;
    }

    .designated_amount_echo .item input {
        flex: 1;
        width: 75px;
        height: 30px;
    }

    .designated_amount_echo .item .operate span {
        margin-right: 15px;
        display: inline-block;
        width: 20px;
        height: 20px;
        padding: 0;
        line-height: 20px;
    }

    .layui-form-label {
        width: 135px;
    }

    .fairy-tag {
        display: flex;
    }

    .fairy-tag-container {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
</style>

<body>
    <div style="padding:0 20px">
        <form class="layui-form" lay-filter="formAjax">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>模板名称
                </label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" placeholder="充值模板名称" required="required"
                        lay-verify="required" autocomplete="off" class="layui-input" value="" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>类型
                </label>
                <div class="layui-input-block" id='select-rebate'>
                    <select name="type" id="type">
                        <option value="">请选择</option>
                        <option value="1">低充</option>
                        <option value="2">中充</option>
                        <option value="3">高充</option>

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>剧集
                </label>
                <div id="pMenu" style="width:100%;flex:1"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>开始收费剧集
                </label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" placeholder="充值模板名称" required="required"
                        lay-verify="required" autocomplete="off" class="layui-input" value="" />
                </div>
            </div>
            <!-- <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>每集收费K币
                </label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="0" title="固定K币">
                    <input type="radio" name="status" value="1" title="区间K币" checked>
                </div>
                <div class="stydom">
                    <label class="layui-form-label item">
                        <span class="x-red">*</span>la<input type="text" name="name" id="name"
                            placeholder="充值模板名称" required="required" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" />-<input type="text" name="name" id="name"
                            placeholder="充值模板名称" required="required" lay-verify="required" autocomplete="off"
                            class="layui-input" value="" />
                    </label>
                </div>
            </div> -->
            <div class="layui-form-item" id="zhidhuichuan">
                <label class="layui-form-label">
                    <span class="x-red">*</span>每集收费K币
                </label>
                <div class="layui-input-block" style="display: flex;align-items: center;">
                    <input type="radio" name="design_switch" value="0" lay-filter="design_switch" title="固定K币" checked>
                    <input type="radio" name="design_switch" value="1" lay-filter="design_switch" title="区间K币">
                </div>
                <div class="layui-input-block designated_amount_echo" style="display: none;"></div>
            </div>
            <blockquote id="phone_tip" style="display: none;" class="layui-elem-quote">移动端暂不支持拖动模板！</blockquote>
            <div class="layui-tab" lay-filter="tabs">
                <ul class="layui-tab-title"> 米
                    <li class="layui-this">已充值用户</li>
                    <li>未充值用户</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-md8 layui-col-space10 gridly" id="recharged_cont">
                                <!-- <div class="layui-col-xs6">
                                    <div class="moneyContent">
                                        <div class="content">
                                            <div>
                                                <span class="title">66元</span>
                                                <span class="tip">首充</span>
                                            </div>
                                            <div>
                                                <span class="startSet">
                                                    6600
                                                    <i>+4800K币</i>
                                                </span>
                                                <span class="tip" style="background-color: #f2f2f2;color:#000">全部用户</span>
                                            </div>
                                        </div>
                                        <div class="foot">
                                            <input type="radio" name="sex" value="1" title="默认勾选" checked="checked">
                                            <div>
                                                <i class="layui-icon layui-icon-edit" style="font-size: 24px;"></i>
                                                <i class="layui-icon layui-icon-delete" style="font-size: 24px;"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div> -->

                            </div>
                        </div>
                        <div class="btn">
                            <button type="button" class="layui-btn" onclick="add(1)">添加商品</button>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row">
                            <div class="layui-col-xs12 layui-col-md8 layui-col-space10 gridly" id="not_recharged_cont">

                            </div>
                        </div>
                        <div class="btn">
                            <button type="button" class="layui-btn" onclick="add(2)">添加商品</button>
                        </div>
                    </div>
                </div>
            </div>


            <input type="hidden" name="id" id="id" value="" />
            <input type="hidden" name="recharged_content" id="recharged_content" value="" />
            <input type="hidden" name="not_recharged_content" id="not_recharged_content" value="" />
            <input type="hidden" name="designated_amount_echo" id="designated_amount_echo"
                lay-verify="designated_amount_echo">
            <button id="submitData" class="layui-btn" lay-submit lay-filter="submitData" style="display: none;" />

        </form>
    </div>
    <script>
        let params = {
            addUrl: '/cps/recharge/add',
            editUrl: '/cps/recharge/edit',
            detailUrl: '/cps/recharge/detail',
            hasCallback: false
        }
        form_ajax(params)
        let phone = false
        if (os.isAndroid || os.isPhone) {
            phone = true
            $('#phone_tip').show()
        }
        // 获取缓存中的数据
        let rc = JSON.parse(sessionStorage.getItem('recharged_content'))
        let nrc = JSON.parse(sessionStorage.getItem('not_recharged_content'))
        let rechargedIndex = 0;
        let not_rechargedIndex = 0;
        // 金额回传
        var designated_amount_echo,
            old_designated_amount_echo;
        layui.use('form', function () {
            var form = layui.form;
            form.verify({
                nums: [
                    /^([1-9][0-9]{0,1}|100)$/, '只能输入1-100的整数'
                ],
                designated_amount_echo: function (value, item) {
                    if (value && form.val("formAjax").design_switch == 1) {
                        let designated_amount_echo = JSON.parse(value);
                        let priceList = []
                        for (let index = 0; index < designated_amount_echo.length; index++) {
                            const element = designated_amount_echo[index];
                            if (element.startSet == '' || element.endSet == '') {
                                return '指定金额回传的金额或回传率不能为空';
                            }
                            priceList.push(element.startSet);
                        }
                        if (isRepeat(priceList))
                            return '指定金额回传存在金额一样的数据';



                    }

                }
            });
            form.on('radio(recharge_template_id)', function (data) {
                $('#recharge').css('display', data.value === '-1' ? 'block' : 'none')
                selectParams2.selected = []
                selectN(selectParams2)
            });
            form.on('radio(design_switch)', function (data) {
                $('.designated_amount_echo').css('display', data.value === '1' ? 'block' : 'none')
            });

        });
        designated_amount_echo = [{
            startSet: '',
            endSet: '',
            currency: ''
        }]
        setAmountEcho()

        // 广告账户ID
        function setInputTag(advertiser_id, disabledAdvertiserId) {
            deleteInputTag()
            $('#advertiser_id').val(advertiser_id.length == 0 ? '' : advertiser_id.toString())
            inputTag({
                elem: '.advertiser_id',
                data: advertiser_id,
                permanentData: disabledAdvertiserId,
                onChange: function (data, value, type) {
                    $('#advertiser_id').val(data.toString())
                }
            })
        }

        // 设置金额回传dom
        function setAmountEcho() {
            let template = '';
            designated_amount_echo.forEach((item, index) => {
                let add = `<span class="layui-badge layui-bg-blue" onclick='addAmountEcho(${index})'>
                    <i class="layui-icon layui-icon-add-1"></i>
                </span>`
                let subtract = `<span class="layui-badge layui-bg-orange" onclick='delAmountEcho(${index})'>
                    <i class="layui-icon layui-icon-subtraction"></i>
                </span>`
                template += `
                    <div class="item">
                        <div class="content">
                            <div>起始-收费集数：<input type="number" autocomplete="off" class="layui-input" value="${item.startSet
                    }" oninput="editAmountEcho('startSet',${index},this)" onblur="editAmountEcho('startSet',${index},this)" />~<input type="number" autocomplete="off" class="layui-input" value="${item.endSet
                    }" oninput="editAmountEcho('endSet',${index},this)" onblur="editAmountEcho('endSet',${index},this)" /></div>
                            <div>收费K币：<input type="number" autocomplete="off" class="layui-input" value="${item.currency
                    }" oninput="editAmountEcho('currency',${index},this)" onblur="editAmountEchos('currency',${index},this)" /></div>
                        </div>

                        <div class="operate">
                            ${index == 0 ? '' : subtract
                    }
                            ${add}
                        </div>
                    </div>
                `
            })
            $('.designated_amount_echo').html(template)
            $('#designated_amount_echo').val(JSON.stringify(designated_amount_echo))
        }
        // 添加回传金额
        function addAmountEcho() {
            if (designated_amount_echo.length < 10) {
                designated_amount_echo.push({ startSet: '', endSet: '' })
            } else {
                layer.msg('最多选择10个')
            }

            setAmountEcho()
        }
        // 删除回传金额
        function delAmountEcho(index) {
            designated_amount_echo.splice(index, 1)
            setAmountEcho()
        }
        // 修改回传
        function editAmountEcho(name, index, that) {
            designated_amount_echo[index][name] = $(that).val()


            // if (id) { // designated_amount_echo[index]['update_time'] = Math.round(new Date().getTime() / 1000)
            //     designated_amount_echo.forEach((item, index) => {
            //         for (let ind = 0; ind < old_designated_amount_echo.length; ind++) {
            //             const it = old_designated_amount_echo[ind];
            //             if (Number(item.startSet) == Number(it.startSet) && Number(item.endSet) == Number(it.endSet)) {
            //                 designated_amount_echo[index]['update_time'] = old_designated_amount_echo[0]['update_time']
            //                 return;
            //             } else {
            //                 designated_amount_echo[index]['update_time'] = Math.round(new Date().getTime() / 1000)
            //             }
            //         }
            //     })
            // }
            $('#designated_amount_echo').val(JSON.stringify(designated_amount_echo))



        }

        function editAmountEchos(name, index, that) {
                for (let i = 0; i < itemVarr.length; i++) {
                    const element = itemVarr[i];
                    templetContent(element,designated_amount_echo)
                }
            
        }


        function deleteInputTag() {
            $("#advertiser_id").val('')
            $('.fairy-tag-container').children().each(function () {
                if ($(this).hasClass('fairy-tag')) {
                    $(this).remove()
                }
            });
        }
        function add(type) {
            rc = JSON.parse(sessionStorage.getItem('recharged_content'));
            nrc = JSON.parse(sessionStorage.getItem('not_recharged_content'))
            if ((rc?.length == 6 && type == 1) || (nrc?.length == 6 && type == 2)) {
                layer.msg('最多选择6个', {
                    icon: 5
                });
                return false
            }
            layui.use('form', function () {
                var form = layui.form;
                sessionStorage.setItem('message', JSON.stringify({
                    name: form.val("formAjax").name,
                    type: form.val("formAjax").type
                }))
                let template_number = 0;
                if (type === 1) {
                    template_number = rc?.length ?? 0
                } else {
                    template_number = nrc?.length ?? 0
                }
                x_admin_show('添加充值项', `./setList.html?type=${type}&template_number=${template_number}`, 1200, 550, null);
            })
        }
        let id = GetQueryString('id')
        if (id) {
            Ajax(params.detailUrl, { id }).then(result => {
                $("#id").val(result.data.id)
                // 当前详情数据
                let rechargedData = result.data.recharged_content ? [...JSON.parse(result.data.recharged_content)] : []
                let not_rechargedData = result.data.not_recharged_content ? [...JSON.parse(result.data.not_recharged_content)] : []
                // 如果缓存有数据 替换
                if (rc) {
                    rechargedData = rc
                }
                if (nrc) {
                    not_rechargedData = nrc
                }
                // sessionStorage.clear()
                sessionStorage.setItem('recharged_content', JSON.stringify(rechargedData))
                sessionStorage.setItem('not_recharged_content', JSON.stringify(not_rechargedData))
                sessionStorage.setItem('message', JSON.stringify({
                    name: result.data.name,
                    type: result.data.type
                }))
                getContent()
            });
        } else {
            getContent()
        }

        function getContent() {
            $('#recharged_cont').html()
            $('#not_recharged_cont').html()
            // 获取设置的缓存数据
            let recharged_content = sessionStorage.getItem('recharged_content')
            let not_recharged_content = sessionStorage.getItem('not_recharged_content')
            let rechargedContent = JSON.parse(recharged_content)
            let not_rechargedContent = JSON.parse(not_recharged_content)
            layui.use(['form', 'element'], function () {
                var form = layui.form;
                var element = layui.element
                setRechargedContent('recharged', rechargedContent, form)
                setRechargedContent('not_recharged', not_rechargedContent, form)
                // if (rechargedContent) {
                //     // 循环创建模板等操作
                //     let rechargedC = ''
                //     let checked = false
                //     rechargedContent.forEach((item, ind) => {
                //         item.checkedName = 'recharged'
                //         item.indexs = ind
                //         let cont = templetContent(item)
                //         rechargedC += cont
                //         if(item.checked == 'checked'){
                //             checked = true
                //         }
                //     })
                //     if(!checked && rechargedContent){
                //         rechargedContent[0]['checked'] = 'checked'
                //     }
                //     $('#recharged_cont').html(rechargedC)
                //     $('#recharged_content').val(JSON.stringify(rechargedContent))
                //     // 单选框事件
                //     form.on('radio(recharged_radio)', function (data) {
                //         rechargedContent.forEach((v, index) => {
                //             if ($(this).attr('data-index') == index) {
                //                 rechargedContent[index].checked = 'checked'
                //             }else{
                //                 rechargedContent[index].checked = ''
                //             }
                //         })
                //         $('#recharged_content').val(JSON.stringify(rechargedContent))
                //         sessionStorage.setItem('recharged_content', JSON.stringify(rechargedContent))
                //     });
                // }

                // if (not_rechargedContent) {
                //     let not_rechargedC = ''
                //     let checked = false
                //     not_rechargedContent.forEach((item, ind) => {
                //         item.checkedName = 'not_recharged'
                //         item.indexs = ind
                //         let cont = templetContent(item)
                //         not_rechargedC += cont
                //         if(item.checked == 'checked'){
                //             checked = true
                //         }
                //     })
                //     if(!checked && not_rechargedContent[0]){
                //         not_rechargedContent[0]['checked'] = 'checked'
                //     }
                //     $('#not_recharged_cont').html(not_rechargedC)
                //     $('#not_recharged_content').val(JSON.stringify(not_rechargedContent))

                //     form.on('radio(not_recharged_radio)', function (data) {
                //         if (not_rechargedContent) {
                //             not_rechargedContent.forEach((v, index) => {
                //                 if ($(this).attr('data-index') == index) {
                //                     not_rechargedContent[index].checked = 'checked'
                //                 }else{
                //                     not_rechargedContent[index].checked = ''
                //                 }
                //             })
                //             $('#not_recharged_content').val(JSON.stringify(not_rechargedContent))
                //             sessionStorage.setItem('not_recharged_content', JSON.stringify(not_rechargedContent))
                //         }
                //     });
                // }
                form.val("formAjax", JSON.parse(sessionStorage.getItem('message')))
                form.render()
                initGridly()
                element.on('tab(tabs)', function () {
                    initGridly()
                });
            })
        }

        //currency  收费K币  sum_currency 总K币 
        function templetContent(params,input) {
            let { id, label, name, original_currency, recharge_price, send_currency, send_title, sum_currency, checked, checkedName, indexs, type } = params
            console.log(params);  
            if(input){
                   for (let i = 0; i < input.length; i++) {
                        
                    
                   }
               }
            let typeTemplate = `
                <span class="startSet">
                    ${original_currency}K币
                    ${send_currency ? `<i>+${send_currency}K币</i>` : ''}
                </span>
            `
            let title = `
                <span class='startSet ellipsis' style='color:#f0ca23'>
                    ${send_title}    
                </span>
            `
            return `<div class="layui-col-xs12 layui-col-md6 brick" style='height:150px' data-message=${JSON.stringify(params)} data-session_name=${checkedName}>
                        <div class="moneyContent">
                            <div class="content">
                                <div>
                                    <span class="title">${name}</span>
                                    <span class="tip" style='${type != 1 ? 'background-color:#f0ca23' : ''}'>${label}</span>
                                </div>
                                <div>
                                    ${type == 1 ? typeTemplate : title}
                                </div>
                            </div>
                            <div class="foot">
                                <!-- <input type="radio" lay-filter="${checkedName}_radio" data-indexs='${indexs}' name="${checkedName}_checked" value="${id}" title="默认勾选" ${checked ? checked : ''}> -->
                               <div></div>
                               
                                <div>
                                    <!-- <i class="layui-icon layui-icon-set-sm setting" style="font-size: 20px;font-weight:bold" data-indexs='${indexs}' data-type='${checkedName}'></i> -->
                                    <i class="layui-icon layui-icon-edit edit" style="font-size: 24px;" data-params='${JSON.stringify(params)}' data-type='${checkedName}_content' data-indexs='${indexs}'></i>
                                    <i class="layui-icon layui-icon-delete delete" style="font-size: 24px;" data-type='${checkedName}_content' data-indexs='${indexs}' ></i>
                                </div>
                            </div>
                        </div>
                    </div>`
        }
        // 删除
        $("body").on("click", ".delete", function () {
            let type = $(this).attr('data-type')
            let template_index = JSON.parse($(this).attr('data-indexs'))
            let temContent = JSON.parse(sessionStorage.getItem($(this).attr('data-type')))
            let now_index = 0;
            temContent.forEach((v, index) => {
                if (template_index == v.indexs) {
                    now_index = index
                }
            })
            layer.confirm('确认要删除吗？', function (layMask) {
                let rc = JSON.parse(sessionStorage.getItem('recharged_content'))
                let nrc = JSON.parse(sessionStorage.getItem('not_recharged_content'))
                type == 'recharged_content' ? rc.splice(now_index, 1) : nrc.splice(now_index, 1)

                if (temContent[now_index].checked == 'checked') {
                    if (type == 'recharged_content') {
                        rechargedIndex = 0
                        if (rc[0]) {
                            rc[0].checked = 'checked'
                        }
                    } else {
                        not_rechargedIndex = 0
                        if (nrc[0]) {
                            nrc[0].checked = 'checked'
                        }
                    }
                }

                sessionStorage.setItem(type, JSON.stringify(type == 'recharged_content' ? rc : nrc))
                getContent()
                layer.close(layMask);
            });
        });
        // 修改
        $("body").on("click", ".edit", function () {
            let params = JSON.parse($(this).attr('data-params'))
            let template_index = $(this).attr('data-indexs')
            let temContent = JSON.parse(sessionStorage.getItem($(this).attr('data-type')))
            console.log('模板修改');
            layui.use(["form", "layer"], function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;
                layer.open({
                    type: 1,
                    title: '编辑',
                    btn: ['保存', '取消'],
                    maxHeight: '500',
                    content: `
                        <div class="x-body moneyTemplate">
                            <blockquote class="layui-elem-quote" style="border-color:#ff5722;color: #db552b;">请勿输入特殊符号！</blockquote>
                            <form class="layui-form editTemplate" lay-filter="editTemplate">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">
                                        <span class="x-red">*</span>名称
                                    </label>
                                    <div class="layui-input-block">
                                        <input type="text" name="name" id="money_name" placeholder="名称" required="required"  lay-verify="required|ZnNum" autocomplete="off" class="layui-input verifyZnNum" value="" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">
                                        <span class="x-red">*</span>充值金额(元)
                                    </label>
                                    <div class="layui-input-block">
                                        <input type="text" name="recharge_price" id="recharge_price" placeholder="充值金额" required="required"
                                            lay-verify="required" autocomplete="off" class="layui-input" value="" />
                                    </div>
                                </div>
                                ${params.type == 1 ?
                            `
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">
                                            <span class="x-red">*</span>充值K币
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="text" name="original_currency" id="original_currency" placeholder="充值K币" disabled autocomplete="off" class="layui-input " value="" />
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">
                                            <span class="x-red">*</span>赠送K币
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="number" name="send_currency" id="send_currency" placeholder="赠送K币" required="required"
                                                lay-verify="required|num" autocomplete="off" class="layui-input verifyNum" value="" pattern="^[0-9]*$" />
                                        </div>
                                    </div>`
                            :
                            `<div class="layui-form-item">
                                        <label class="layui-form-label">
                                            <span class="x-red">*</span>赠送标语
                                        </label>
                                        <div class="layui-input-block">
                                            <input type="text" name="send_title" id="send_title" placeholder="赠送标语" required="required"
                                                lay-verify="required|ZnNum" autocomplete="off" class="layui-input verifyZnNum" value="" />
                                        </div>
                                    </div>`
                        }
                                
                                <div class="layui-form-item">
                                    <label class="layui-form-label">
                                        标签
                                    </label>
                                    <div class="layui-input-block">
                                        <input type="text" name="label" id="label" placeholder="标签"
                                            lay-verify="ZnNum" autocomplete="off" class="layui-input verifyZnNum" value="" />
                                    </div>
                                </div>
                                
                                <input type="hidden" name="id" id="id" value="" />
                                <input type="hidden" name="indexs" value="" />
                                <input type="hidden" name="checkedName" value="" />
                                <button id="submitTemplate" class="layui-btn" lay-submit lay-filter="submitTemplate"  lay-on="get-jy" style="display: none;" />
                                
                            </form>
                        </div>
                    `,
                    yes: function (layMask) {
                        let data = form.val("editTemplate")
                        let now_template = {};
                        temContent.forEach((v, index) => {
                            if (template_index == v.indexs) {
                                now_template = temContent[index]
                            }
                        })

                        if ($("#money_name").val() == '') {
                            layer.msg('名称不能为空！', { icon: 5, time: 2000 })
                            return;
                        }
                        if (Number($("#recharge_price").val()) <= 0) {
                            layer.msg('金额不能为0！', { icon: 5, time: 2000 })
                            return;
                        }

                        layui.use('form', function () {
                            var form = layui.form;
                            form.verify({
                                ZnNum: function (value, item) { //value：表单的值、item：表单的DOM对象
                                    // var patter_special_char = /[,;；，"’'`·《》[\\]]+/;
                                    // if(value.match(patter_special_char) != null){
                                    //     return '请勿输入特殊符号！';
                                    // }
                                    var regEn = /[`!@#$%^&*()_<>?:"{}\/;'[\]]/im,
                                        regCn = /[·！#￥（——）：；“”‘|《。》？【】[\]]/im;
                                    if (regEn.test(value) || regCn.test(value)) {
                                        return '请勿输入特殊符号！';
                                    }
                                }
                                , num: [
                                    /^[0-9]*$/
                                    , '只能输入数字！'
                                ]
                            });
                        });
                        if (form.validate('.editTemplate')) {
                            // temContent.forEach((v,i)=>{
                            //     if(Number(v.id) === Number(data.id)){
                            //         Object.keys(data).forEach((item,index)=>{
                            //             v[item] = Object.values(data)[index]
                            //         })
                            //         v.sum_currency = Number(v.original_currency) + Number(v.send_currency)
                            //     }
                            // })
                            Object.keys(data).forEach((item, index) => {
                                now_template[item] = Object.values(data)[index]
                            })
                            now_template.sum_currency = Number(now_template.original_currency) + Number(now_template.send_currency)
                            sessionStorage.setItem(data.checkedName + '_content', JSON.stringify(temContent))
                            $('#' + data.checkedName + '_content').val(JSON.stringify(temContent))
                            getContent()
                            layer.close(layMask)
                        }

                    }
                });
                form.val("editTemplate", params);
                $("#recharge_price").on('input propertychange', function (e) {
                    $("#original_currency").val((clearNoNum($(this)) * 100).toFixed())
                })
            });

        });
        // 设置
        $("body").on("click", ".setting", function () {
            let type = $(this).attr('data-type') == 'recharged' ? 1 : 2
            let index = $(this).attr('data-indexs')
            sessionStorage.setItem(type + '_index', index)
            x_admin_show('修改充值项', `./setList.html?type=${type}&seting=${index}`, 1200, 550, null);
        });

        function clearNoNum(that) {
            let num = that.val()
            num = num.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符   
            num = num.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的   
            num = num.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数   
            if (num.indexOf(".") < 0 && num != "") {
                num = parseFloat(num);
            }
            that.val(num)
            return num
        }

        let selectParams = {
            url: '/cps/video/select',
            selected: [],
            tips: '选择短剧',
            name: 'video_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu'
        }

        Ajax(params.detailUrl, { id }).then(result => {
            selectParams.selected = [result.data.video_id]
            selectN(selectParams)
        });

        // 设置拖拽
        function initGridly() {
            if (!phone) {
                $('.gridly').gridly({
                    base: 64, // px 
                    gutter: 8, // px
                    columns: 12,
                    callbacks: { reordered }  //拖拽后回调函数
                });
            }
        }
        var reordered = function ($elements) {
            //当前拖拽对象
            var currentObj = this.reordered.arguments[1];
            if (typeof (currentObj) != "undefined") {
                //拖拽后模块数组
                var arr = $elements;
                let message = []
                let session_name = ''

                arr.each((index, item) => {
                    let message_item = $(item).data('message');
                    let nowIndex = $(item).data('session_name') == 'recharged' ? rechargedIndex : not_rechargedIndex;
                    message_item.checked = ''
                    message.push(message_item)
                    session_name = $(item).data('session_name')
                    if (index == 0) {
                        message_item.checked = 'checked'
                    } else {
                        message_item.checked = ''
                    }
                })
                sessionStorage.setItem(session_name + '_content', JSON.stringify(message))
                $('#' + session_name + '_content').val(JSON.stringify(message))

            }
        }
        var itemVarr = []
        // 创建模板
        function setRechargedContent(name, content, form) {
            if (content) {
                // 循环创建模板等操作
                let rechargedC = ''
                let checked = false
                content.forEach((item, ind) => {
                    item.checkedName = name
                    item.indexs = ind
                    itemVarr.push(item)
                    let cont = templetContent(item)
                    rechargedC += cont
                    if (item.checked == 'checked') {
                        checked = true
                    }
                    item.checked = ''
                })
                if (content[0]) {
                    content[0]['checked'] = 'checked'
                }
                $(`#${name}_cont`).html(rechargedC)
                $(`#${name}_content`).val(JSON.stringify(content))
                sessionStorage.setItem(`${name}_content`, JSON.stringify(content))
                // 单选框事件
                form.on(`radio(${name}_radio)`, function (data) {
                    let this_index = $(this).parent().parent().parent().index();
                    let conts = JSON.parse(sessionStorage.getItem(`${name}_content`))
                    let data_index = $(this).attr('data-indexs')
                    conts.forEach((v, index) => {
                        conts[0].checked = 'checked';
                    })
                    $(`#${name}_content`).val(JSON.stringify(conts))
                    sessionStorage.setItem(`${name}_content`, JSON.stringify(conts))
                });
            }
        }

        $("body").on("keypress", "input", function (e) {
            if (e.which === 32 || e.which == 13) {
                return false;
            }
        });
    </script>

</body>

</html>